﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Central.Linq.Mvc.Demo.Models;
using SampleData;

namespace Central.Linq.Mvc.Demo.Controllers {

	public class HomeController : PreparableController<PersonViewModel> {
		private List<Person> _people;

		#region конструктор

		public HomeController(PreparableFiltersManager filterManager)
			: base(filterManager) {
			_people = People.GetPeople();
		}

		#endregion конструктор

		public ActionResult Index(int? id) {
			ViewBag.Fields = ModelInfoManager.FieldInformations;
			var fieldSetDefault = ModelInfoManager.DefaultFieldManager;

			// для демонстрации работы менеджера -------------------
			var fieldSetAll = ModelInfoManager["All"];
			var fieldSetAdmin = ModelInfoManager["Admin"];
			// ------------------------------------------------------

			IndexPageViewModel _model = new IndexPageViewModel(this.Filters, id, _people.AsQueryable());
			return View(_model);
		}

		public ActionResult Index2(int? id) {
			ViewBag.Fields = ModelInfoManager.FieldInformations;
			IndexPageViewModel _model = new IndexPageViewModel(this.Filters, id, _people.AsQueryable());
			return View(_model);
		}

		protected override InfoManager InitializeInfoManager() {
			return new PersonInfoManager();
		}

		protected override string SetUserName() {
			return User.Identity.Name;
		}
	}
}